<?php

/**
 * File :: VFS (Virtual File System) :: File
 *
 * Native PHP File interface for the Virtual File System
 * 
 * Warlock is free software. This version may have been modified pursuant
 * to the GNU General Public License, and as distributed it includes or
 * is derivative of works licensed under the GNU General Public License or
 * other free or open source software licenses.
 *
 * @package    warlock
 * @author     David Cole <neophyte@sourcetutor.com>
 * @license    GNU/GPL v2
 */

// Class Dependencies
using('Library.File.VFS.Common');

class File_VFS_File extends File_VFS_Common 
{
    var $_cwd;
    
    function __construct($cwd)
    {
        parent::__construct();
    }
    
    function mkdir($path)
    {
        return @mkdir($this->_getNativePath($path), 0700, true);
    }
    
    function mv($source, $destination)
    {
        /*
         * Format the source and destination locations so they'll
         * work as expected with the PHP file functions.
         */
        
        $source      = $this->_getNativePath($source);
        $destination = $this->_getNativePath($destination);
        
        if (substr($destination, -1) == '/')
            $destination .= substr($source, strrpos($source, '/'));
                        
        /*
         * Ensure the destination directory exists before moving the
         * source file or directory.
         */
        
        $dir = dirname($destination);
        
        if (!file_exists($dir))
        {
            if (!$this->mkdir($dir))
                return false;
        }
        else 
            if (is_file($dir))
                return false;
            
        /*
         * Finally lets move the source file or directory tot he specified
         * destination.
         */
        
        return @rename($source, $destination);
    }
    
    function cp()
    {
        
    }
    
    function rm()
    {
        
    }
    
    function chmod()
    {
        
    }
    
    function cwd()
    {
        
    }
    
    function ls()
    {
        
    }
    
    function read()
    {
        
    }
    
    function write()
    {
        
    }
    
    function size()
    {
        
    }
    
    function _getNativePath($location)
    {
        return W_ENV_PATH.(($location[0] == '/')?$location:'/'.$location);
    }
}

?>